\section{Functions}

\subsection{Initialization}
\label{initialisierung}
Before using the system, it must be initialized. The required tables are built, the consistency is checked, deprecated pages will be deleted and consolidated. The function is called with \textit{Fee\_init}. No parameter are needed. It returns an error code that can be evaluated accordingly. (chapter \ref{fehlercodes})

\begin{mdframed}\begin{tabbing}
	\hspace{1cm} \= \hspace{1cm} \= \kill
	FTL001\_StatusType \textbf{Fee\_init}(void) \\
	\\
	\> Initializes the system. \\
	\\
	\> \textbf{Parameter:} \\
	\> \> None. \\
	\> \textbf{Returns:} \\
	\> \> FTL001\_StatusType - Errorcode
\end{tabbing}\end{mdframed}

\subsection{Write data}
Any amount of data could be written with the function \textit{Fee\_write} at any memory adress. Parameters are the address, a pointer to the array and the length of the given array. An error code will be returned.

\begin{mdframed}\begin{tabbing}
	\hspace{1cm} \= \hspace{1cm} \= \kill
	FTL001\_StatusType \textbf{Fee\_write}(uint32\_t address, uint16\_t *Data, uint32\_t length) \\
	\\
	\> Writes an array with given length to given address. \\
	\\
	\> \textbf{Parameter:} \\
	\> \> address - address on which the data should be written \\
	\> \> Data - Data array \\
	\> \> length - length of the Data array \\
	\> \textbf{Returns:} \\
	\> \> FTL001\_StatusType - Errorcode
\end{tabbing}\end{mdframed}

\begin{table}[!htb]
	\centering
		\begin{tabular}{|l|l|l|}\hline
			\textbf{Operation} & \textbf{Content} & \textbf{Target} \\\hline\hline

			\multicolumn{3}{|l|}{New sector, new page} \\\hline
			Write & Header 1 & Data sector \\\hline
			Write & Data & Data sector \\\hline
			Write & Header 2 & Data sector \\\hline
			\multicolumn{3}{|r|}{Write: 3 pages (768 Byte)} \\\hline\hline
			
			\multicolumn{3}{|l|}{Existent sector, new page} \\\hline
			Read & Header 2 & Data sector \\\hline
			Write & Data & Data sector \\\hline
			Write & Header 2 & Data sector \\\hline			
			\multicolumn{3}{|r|}{Write: 2 pages (512 Byte), Read: 1 page (256 Byte)} \\\hline\hline
			
			\multicolumn{3}{|l|}{Existent sector, existent page -> new replacement sector, new page} \\\hline
			Read & Header 2 & Data sector \\\hline
			Write & Header 1 & Replacement sector \\\hline
			Write & Data & Replacement sector \\\hline
			Write & Header 2 & Replacement sector \\\hline
			Write & Header 2 & Data sector \\\hline
			\multicolumn{3}{|r|}{Write: 4 pages (1024 Byte), Read: 1 page (256 Byte)} \\\hline\hline
			
			\multicolumn{3}{|l|}{Existent replacement sector, new page} \\\hline
			Read & Header 2 & Data sector \\\hline
			Read & Header 2 & Replacement sector \\\hline
			Write & Data & Replacement sector \\\hline
			Write & Header 2 & Replacement sector \\\hline
			\multicolumn{3}{|r|}{Write: 2 pages (512 Byte), Read: 2 pages (512 Byte)} \\\hline\hline

			\multicolumn{3}{|l|}{Existent replacement sector, no free pages -> merge} \\\hline
			Write & Header 1 & New data sector\\\hline
			Read & Header 2 & Old Data sector \\\hline
			Read & Header 2 & Replacement sector \\\hline
			Write & Data & New data sector (up to 256x)\\\hline
			Write & Header 2 & New data sector \\\hline
			Write & Header 1 & Replacement sector \\\hline
			Write & Header 1 & Old data sector \\\hline
			Write & Header 1 & New data sector \\\hline
			\multicolumn{3}{|r|}{Write: 6-260 pages (1536-66560 Byte), Read: 2 pages (512 Byte)} \\\hline			
		\end{tabular}
	\caption{Overview over operations during write process}
	\label{tab:writeops}
\end{table}

\newpage
\newpage

\subsection{Read data}
With \textit{Fee\_read} any amount of data could be read out of the memory. Parameters are the memory address, a pointer to  the array in which the data should be stored and the amount of bytes which should be read. An error code will be returned.

\begin{mdframed}\begin{tabbing}
	\hspace{1cm} \= \hspace{1cm} \= \kill
	FTL001\_StatusType \textbf{Fee\_read}(uint32\_t address, uint16\_t *Data, uint32\_t length) \\
	\\
	\> Reads an array with given length from given address. \\
	\\
	\> \textbf{Parameter:} \\
	\> \> address - address on which the data should be read \\
	\> \> Data - Data array \\
	\> \> length - length of the Data array \\
	\> \textbf{Returns:} \\
	\> \> FTL001\_StatusType - Errorcode
\end{tabbing}\end{mdframed}

\begin{table}[!htb]
	\centering
		\begin{tabular}{|l|l|l|}\hline
			\textbf{Operation} & \textbf{Content} & \textbf{Target} \\\hline\hline

			\multicolumn{3}{|l|}{Page empty} \\\hline
			Read & Header 2 & Data sector \\\hline
			\multicolumn{3}{|r|}{Read: 1 pages (256 Byte)} \\\hline\hline
			
			\multicolumn{3}{|l|}{Page in data sector} \\\hline
			Read & Header 2 & Data sector \\\hline
			Read & Data & Data sector \\\hline
			\multicolumn{3}{|r|}{Read: 2 pages (512 Byte)} \\\hline\hline
			
			\multicolumn{3}{|l|}{Page in replacement sector} \\\hline
			Read & Header 2 & Data sector \\\hline
			Read & Header 2 & Replacement sector \\\hline
			Read & Data & Replacement sector \\\hline
			\multicolumn{3}{|r|}{Read: 3 pages (768 Byte)} \\\hline\hline
		\end{tabular}
	\caption{Overview over operations during read process}
	\label{tab:readops}
\end{table}

\newpage

\subsection{Format device}
To format the system, the function \textit{Fee\_format\_device} must be called. All sectors will be erased and the allocation of the logical to the physical sectors will be reset. The number of erase cycles will be raised by one. This function can be called before the initialization but after the configuration. No parameters are needed. An error code will be returned.

\begin{mdframed}\begin{tabbing}
	\hspace{1cm} \= \hspace{1cm} \= \kill
	FTL001\_StatusType \textbf{Fee\_format\_device}(void) \\
	\\
	\> Erase the whole device. \\
	\\
	\> \textbf{Parameter:} \\
	\> \> None. \\
	\> \textbf{Returns:} \\
	\> \> FTL001\_StatusType - Errorcode
\end{tabbing}\end{mdframed}

\newpage

\subsection{Getting the status}
Two functions allow the detection of the status. CFI information of the flash chip is read out with \textit{FTL001\_GetCFIInfo}. Parameter of this function are a pointer to the global handler and a pointer to a variable which stores the information. The function \textit{Fee\_get\_status} reads the status of the system.  Here, the minimum and maximum number of erase cycles of all sectors and the number of free sectors are written to the variable referred to by the pointer passed as a parameter.

\begin{mdframed}\begin{tabbing}
	\hspace{1cm} \= \hspace{1cm} \= \kill
	FTL001\_StatusType \textbf{FTL001\_GetCFIInfo}\\
	\>(const FTL001\_HandleType* Handle, FTL001\_CFIInfoType* CFIInfo) \\
	\\
	\> Reads CFI-Informations. \\
	\\
	\> \textbf{Parameter:} \\
	\>\> Handle - Pointer to global Handler \\
	\>\> CFIInfo - Poiner to variable for CFI informations \\
	\> \textbf{Returns:} \\
	\>\> FTL001\_StatusType - Errorcode
\end{tabbing}\end{mdframed}

\begin{mdframed}\begin{tabbing}
	\hspace{1cm} \= \hspace{1cm} \= \kill
	FTL001\_StatusType \textbf{Fee\_get\_status}(FEE\_StatusType *fee\_status) \\
	\\
	\> Returns status of the emulation system. \\
	\\
	\> \textbf{Parameter:} \\
	\> \> fee\_status - Variable to store the information \\
	\> \textbf{Returns:} \\
	\> \> FTL001\_StatusType - Errorcode
\end{tabbing}\end{mdframed}